import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
const routes = [{
        path: "/",
        name: "login",
        component: () =>
            import ("./../views/Login.vue")
    },
    {
        path: "/learn",
        name: "learn",
        component: () =>
            import ("./../views/Learn.vue")
    },
    {
        path: "/allskill",
        name: "allskill",
        component: () =>
            import ("./../views/AllSkill.vue")
    },
    {
        path: "/colors",
        name: "color",
        component: () =>
            import ("./../components/setColors/color.vue")
    },
    {
        path: "/echarts",
        name: "echarts",
        component: () =>
            import ("./../components/Echarts/Echarts.vue")
    },
    {
        path: "/tips",
        name: "tips",
        component: () =>
            import ("./../components/timeTips/tips.vue")
    },
    {
        path: "/bscroll",
        name: "bscroll",
        component: () =>
            import ("./../views/bscroll.vue")
    },

    {
        path: "/shopping",
        name: "shopping",
        component: () =>
            import ("./../components/shop/shoppingComponent.vue")
    },

    {
        path: "/main",
        name: "main",
        redirect: "/mainContent",
        component: () =>
            import ("./../views/Main.vue"),
        children: [{
                path: "/mainContent",
                name: "/mainContent",
                component: () =>
                    import ("./../components/mainContent.vue")
            },

            {
                path: "/information",
                name: "information",
                // redirect: '/shopinformation',
                component: () =>
                    import ("./../components/informationComponent.vue")
            }
        ]
    }
];

const router = new VueRouter({
    mode: "history",
    routes
});
router.beforeEach((to, from, next) => {
    const isLogin = localStorage.haveLogin ? true : false;
    if (to.path == "/") {
        next();
    } else {
        isLogin ? next() : next("/");
    }
});
export default router;